import model = require("index.model");

export class EventMgr {
	public registerKkNeeded(handler: (args: KkNeededEventArgs) => void) {
		if(this._kkNeeded) console.warn('The event KkNeeded was registered more than one time.');
		this._kkNeeded = handler;
	}
	
	public registerTopicNeeded(handler: (args: TopicNeededEventArgs) => void) {
		if(this._topicNeeded) console.warn('The event TopicNeeded was registered more than one time.');
		this._topicNeeded = handler;
	}

	public registerCommentsNeeded(handler: (args: CommentsNeededEventArgs) => void) {
		if(this._commentsNeeded) console.warn('The event CommentsNeeded was registered more than one time.');
		this._commentsNeeded = handler;
	}
	
	public registerRated(handler: (args: RatedEventArgs) => void) {
		if(this._rated) console.warn('The event Rated was registered more than one time.');
		this._rated = handler;
	}
	
	public registerTopicSelected(handler: (args: TopicSelectedEventArgs) => void) {
		if(this._topicSelected) console.warn('The event TopicSelected was registered more than one time.');
		this._topicSelected = handler;
	}
	
	public registerKkSubmitted(handler: (args: KkSubmittedEventArgs) => void) {
		if(this._kkSubmitted) console.warn('The event KkSubmitted was registered more than one time.');
		this._kkSubmitted = handler;
	}
	
	public registerKaSubmitted(handler: (args: KaSubmittedEventArgs) => void) {
		if(this._kaSubmitted) console.warn('The event KaSubmitted was registered more than one time.');
		this._kaSubmitted = handler;
	}
	
	public registerCmtSubmitted(handler: (args: CmtSubmittedEventArgs) => void) {
		if(this._cmtSubmitted) console.warn('The event CmtSubmitted was registered more than one time.');
		this._cmtSubmitted = handler;
	}
	
	public registerRemoveKa(handler: (args: RemoveKaEventArgs) => void) {
		if(this._removeKa) console.warn('The event RemoveKa was registered more than one time.');
		this._removeKa = handler;
	}
	
	public registerRemoveCmt(handler: (args: RemoveCmtEventArgs) => void) {
		if(this._removeCmt) console.warn('The event RemoveCmt was registered more than one time.');
		this._removeCmt = handler;
	}
	
	
	public kkNeeded(args: KkNeededEventArgs) {
		if(this._kkNeeded) this._kkNeeded(args);
		console.log('kkNeeded', args);
	}
	
	public topicNeeded(args: TopicNeededEventArgs) {
		if(this._topicNeeded) this._topicNeeded(args);
		console.log('topicNeeded', args);
	}
	
	public commentsNeeded(args: CommentsNeededEventArgs) {
		if(this._commentsNeeded) this._commentsNeeded(args);
		console.log('commentsNeeded', args);
	}
	
	public rated(args: RatedEventArgs) {
		if(this._rated) this._rated(args);
		console.log('rated', args);
	}
	
	public topicSelected(args: TopicSelectedEventArgs) {
		if(this._topicSelected) this._topicSelected(args);
		console.log('topicSelected', args);
	}
	
	public kkSubmitted(args: KkSubmittedEventArgs) {
		if(this._kkSubmitted) this._kkSubmitted(args);
		console.log('kkSubmitted', args);
	}
	
	public kaSubmitted(args: KaSubmittedEventArgs) {
		if(this._kaSubmitted) this._kaSubmitted(args);
		console.log('kaSubmitted', args);
	}
	
	public cmtSubmitted(args: CmtSubmittedEventArgs) {
		if(this._cmtSubmitted) this._cmtSubmitted(args);
		console.log('cmtSubmitted', args);
	}
	
	public removeKa(args: RemoveKaEventArgs) {
		if(this._removeKa) this._removeKa(args);
		console.log('removeKa', args);
	}
	
	public removeCmt(args: RemoveCmtEventArgs) {
		if(this._removeCmt) this._removeCmt(args);
		console.log('removeCmt', args);
	}
	
	private _kkNeeded: (args: KkNeededEventArgs) => void;
	private _topicNeeded: (args: TopicNeededEventArgs) => void;
	private _commentsNeeded: (args: CommentsNeededEventArgs) => void;
	private _rated: (args: RatedEventArgs) => void;
	private _topicSelected: (args: TopicSelectedEventArgs) => void;
	private _kkSubmitted: (args: KkSubmittedEventArgs) => void;
	private _kaSubmitted: (args: KaSubmittedEventArgs) => void;
	private _cmtSubmitted: (args: CmtSubmittedEventArgs) => void;
	private _removeKa: (args: RemoveKaEventArgs) => void;
	private _removeCmt: (args: RemoveCmtEventArgs) => void;
}


export class KkNeededEventArgs {
	public id: number;
	public out: model.Konsenskiste;
}

export class TopicNeededEventArgs {
	public id: number;
	public out: model.Topic;
}

export class CommentsNeededEventArgs {
	public parent: model.QkCommentable;
}

export class RatedEventArgs {
	public postId: number;
	public rating: string;
	public then: (string) => void;
}

export class TopicSelectedEventArgs {
	public id: number;
}

export class KkSubmittedEventArgs {
	public title: string;
	public text: string;
	public parent: model.Topic;
	public out: model.Konsenskiste;
}

export class KaSubmittedEventArgs {
	public title: string;
	public text: string;
	public context: string;
	public parent: model.Konsenskiste;
	public out: model.Kernaussage;
}

export class CmtSubmittedEventArgs {
	public text: string;
	public parent: model.QkMainElement;
	//public out: model.Kommentar;
}

export class RemoveKaEventArgs {
	public ka: model.Kernaussage;
}

export class RemoveCmtEventArgs {
	public cmt: model.QkComment;
}